﻿using UnityEngine;
using System.Collections;
using strange.extensions.mediation.impl;
using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using System;

namespace NormalBattleIoc
{
    public class WinPanelMediator : Mediator
    {
        [Inject]
        public WinPanelView view { get; set; }

        [Inject(ContextKeys.CONTEXT_DISPATCHER)]//全局的dispatcher
        public IEventDispatcher dispatcher { get; set; }

        /// <summary>
        /// 这里做初始化的操作，相当于start
        /// </summary>
        public override void OnRegister()
        {
            // view.ShowThisUI();

            AddWinButtonClickFunc();

             dispatcher.AddListener(BattleUIEvent.ShowWinPanel, OnShowWinPanel);

            // dispatcher.AddListener(BattleUIEvent.Close_All_Panel, OnCloseAll_Panel);
        }

        private void OnShowWinPanel(IEvent payload)
        {
            view.ShowThisUI();
        }

        void AddWinButtonClickFunc()
        {
            if (view.back_win != null)
            {
                view.back_win.onClick.AddListener(delegate ()
                {

                    SceneLoadManager.Instance.BackToPrevScene();
                    //dispatcher.Dispatch(PersonOperationEvent.Attack);
                   // view.CloseThisUI();
                });
            }
        }
    }
}
